package edu.hunau.cxb19.oop.class25;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.junit.Test;

/**
 *
 * @author hb
 *
 *         2020-03-30 16:12:50
 */
public class ByteStreamTest {

	@Test
	public void createFile() throws Exception {
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(".\\demo01\\out01.txt");
		} catch (FileNotFoundException e) {
			throw e;
		} finally {
			if (fos != null) {
				// 物理资源必须手动释放
				fos.close();
			}
		}
	}
	@Test
	public void createFileJdk7()throws Exception{
		//try-with-resource保证FileOutputStream物理资源的释放
		 try(FileOutputStream  fos = new FileOutputStream(".\\demo\\out01.txt",true);){
			 //将字符a写入到out01.txt文件
			 fos.write('\n');
			 fos.write(97);
			 fos.write("你是一个好人,hehe".getBytes());
			 fos.write('\n');
			 fos.flush();
			 
		 }catch(Exception e) {
			 throw e;
		 }
	}
}
